﻿using System.Configuration;
using System.Text.RegularExpressions;
using System.Web;

namespace Web
{
    /// <summary>
    /// Handler2 的摘要说明
    /// </summary>
    public class Handler2 : IHttpHandler
    {
        public static string RemoveHtmlTags(string inputStr)
        {
            if (string.IsNullOrEmpty(inputStr)) return null;
            Regex regex = new Regex(@"<[^>]+>|</[^>]+>");
            return regex.Replace(inputStr, "");
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string res = "ok";

            var phone = RemoveHtmlTags(context.Request.Form["mobile"]);
            if (!ValidateHelper.IsMobile(phone))
            {
                res = "请输入正确的手机号！";
            }
            else
            {
                var html = $"对方手机号：{phone}";

                var recieve = ConfigurationManager.AppSettings["RecieveEmailAccount"];
                new EmailService().Send(recieve, "有人电话申请", html);
            }

            context.Response.Write(res);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}